﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;


    public class CalendarTransaction
    {
        public DateTime Date { get; set; }
        private string title { get; set; }
        public string Title
        {
            get
            {
                return title;
            }
            set
            {
                title = value;
                string[] titleParts = title.Split('(', ')');
                Company = titleParts[0];
                bool positive = titleParts[1][0] == '+';
                Value = Decimal.Parse(titleParts[1].Substring(positive ? 2 : 1));
                if (positive)
                    TransactionType = TransactionType.Paycheck;
                else
                {
                    TransactionType = TransactionType.Bill;
                    Value *= -1;
                }

            }
        }
        public decimal Value { get; set; }
        public string Company { get; set; }
        public TransactionType TransactionType { get; set; }
        public CalendarTransaction()
        {
        }
        public CalendarTransaction(string company, decimal value, DateTime date, TransactionType transactionType)
        {
            Company = company;
            Value = value;
            Date = date;
            TransactionType = transactionType;
        }
        public CalendarTransaction[] SplitBill(decimal smallerPercent)
        {
            CalendarTransaction[] tempArray = new CalendarTransaction[2];
            decimal smallerValue = smallerPercent * Value;
            decimal largerValue = Value - smallerValue;
            tempArray[0] = new CalendarTransaction(Company + " (small chunk)", smallerValue, Date, TransactionType);
            tempArray[1] = new CalendarTransaction(Company + " (large chunk)", largerValue, Date, TransactionType);
            return tempArray;
        }

    }
    public class CalendarTransactionComparer : IComparer<CalendarTransaction>
    {
        public int Compare(CalendarTransaction x, CalendarTransaction y)
        {
            if (x.TransactionType == y.TransactionType)
                return 0;
            else if (x.TransactionType == TransactionType.Paycheck)
                return -1;
            else
                return 1;
        }
    }
    public enum TransactionType
    {

        Bill,
        Paycheck
    }
